<template>
	<view class="p-3 bg-white">
		<view class="flex j-sb a-center mb-3">
			<view class="font-bold">调拨清单</view>
			<!-- <view class="flex j-start a-center" v-if="listsData.length!=0">
				<view class="flex j-start a-center" @click="handleDelAll">
					<u-icon name="trash" color="#888" size="16"></u-icon>
					<view class="ml-1 text-secondary">全部清除</view>
				</view>
				<view class="flex j-start a-center ml-2" @click="navigateTo('pages/warehouse/outbound/export')">
					<u-icon name="arrow-downward" color="#00B0FF" size="16"></u-icon>
					<view class="ml-1 text-primary">导出清单</view>
				</view>
			</view> -->
		</view>

		<view v-if="listsData.length!=0">
			<view class="py-1 px-2 border rounded-10 mb-2" v-for="(item,index) in listsData" :key="index"
				@click="navigateTo('pages/warehouse/product/detail?productCode='+item.productCode)">
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">所在仓库：</view>
					<view>{{item.warehouseName}}</view>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">商品编码：</view>
					<view>{{item.productCode}}</view>
					<image src="@/static/images/fuzhi.png" mode="widthFix" class="svgmini ml-3"
						@click.stop="utils.setClipboardData(item.productCode)"></image>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">手机型号：</view>
					<view>{{item.model}}</view>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">手机品牌：</view>
					<view>{{item.brand}}</view>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">内存：</view>
					<view>{{item.memory}}</view>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">颜色：</view>
					<view>{{item.colour}}</view>
				</view>
				<view class="flex j-start a-center my-2" >
					<view class="text-right col-170">IMEI：</view>
					<view class="flex-1">{{item.imei?item.imei:'--'}}</view>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">机况：</view>
					<view class="flex-1">{{item.subrackDesc?item.subrackDesc:'--'}}</view>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">库龄：</view>
					<view>{{item.storageAge?item.storageAge:'--'}}</view>
				</view>
				
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">成本价：</view>
					<view>{{item.costPrice}}</view>
				</view>
			<!-- 	<view class="flex j-start a-center my-2">
					<view class="text-right col-170">销售价：</view>
					<view>{{item.salePrice}}</view>
				</view> -->
				<view class="flex j-end a-center my-2">
					<!-- <view class="btn" @click.stop="handleEdit(index,item)">修改销售价</view> -->
					<view class="btn-plain ml-3" @click.stop="handleDel(index,item)">删除</view>
				</view>
			</view>
		</view>
		<empty v-else />

		<view style="height: 150rpx;"></view>
		<view class="position-fixed w-100 left-0 flex j-center a-center bg-white p-5" style="bottom: 0rpx;">
			<view v-if="listsData.length==0" class="btn m-o col-8 rounded-40 " style="height: 70rpx;"
				@click="navigateTo('pages/warehouse/allot/edit')">添加商品</view>
			<view v-if="listsData.length!=0" class="btn m-o col-8 rounded-40 " style="height: 70rpx;"
				@click="navigateTo('pages/warehouse/allot/submit')">下一步</view>
		</view>

		<!-- 修改销售价 -->
		<u-popup :show="showPopup" @close="showPopup=false" mode="center" :round="10" closeable
			:closeOnClickOverlay="false">
			<view class="col-11 py-5 px-3">
				<view class="flex j-start a-center mb-3">
					<view class="text-right font-md" style="width:190rpx">原销售价：</view>
					<view class="font-lg">￥{{listsData[currentIndex]&&listsData[currentIndex].salePrice}}</view>
				</view>
				<view class="flex j-start mb-4">
					<view class="text-right font-md" style="width:190rpx">销售价：</view>
					<view class="flex-1">
						<u--input placeholder="请输入请输入销售价" border="surround" v-model="biddingPrice"></u--input>

					</view>
				</view>
				<view class="btn m-o col-5 rounded-40" style="height: 70rpx;" @click="handleSubmitQuote">确定</view>

			</view>
		</u-popup>

	</view>
</template>

<script>
	import {
		allotSaleList,editOutboundStatus,cleanOutData
	} from '@/common/api/sales.js'
	export default {
		name: "",
		mixins: [],
		data() {
			return {
				showPopup: false,
				currentIndex: 0,
				biddingPrice: '',

			}
		},
		onShow() {
			this.getSaleList()
		},
		onPullDownRefresh() {
			this.getSaleList()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 500);
		},
		watch: {},
		computed: {},
		methods: {
			handleEdit(index) {
				this.currentIndex = index;
				this.showPopup = true
			},
			getSaleList() {
				this.listsData = [];
				allotSaleList().then(res => {
					this.listsData = res.data
				})
			},
			handleDel(index, item) {
				uni.showModal({
					title: '提示',
					content: '确定要删除该信息吗？',
					success: res => {
						if (res.confirm) {
							editOutboundStatus({
								id: this.listsData[this.currentIndex].id,
								isOutbound: 0
							}).then(res=>{
								uni.$u.toast('删除成功');
								this.getSaleList()
							})
						} else if (res.cancel) {
			
						}
					}
				});
			},
			handleDelAll(){
				let ids=this.listsData.map(i=>i.id);
				uni.showModal({
					title: '提示',
					content: '确定要全部删除吗？',
					success: res => {
						if (res.confirm) {
							cleanOutData(ids).then(res=>{
								uni.$u.toast('删除成功');
								this.getSaleList()
							})
						} else if (res.cancel) {
							
						}
					}
				});
			},
			handleSubmitQuote(){
				editOutboundStatus({
					id: this.listsData[this.currentIndex].id,
					isOutbound: 2,
					salePrice: this.biddingPrice
				}).then(res=>{
					uni.$u.toast('修改成功');
					this.getSaleList()
					this.showPopup = false;
					this.biddingPrice=''
				})
			}
		}
	}
</script>

<style lang="scss">
	.colorF {
		color: #4F4F4F;
	}
</style>